package com.aifund.admin.controller;

import com.aifund.admin.entity.form.config.ConfigPageForm;
import com.aifund.admin.entity.vo.PageResult;
import com.aifund.admin.service.SystemConfigAdminService;
import com.aifund.common.entity.SystemConfig;
import com.aifund.common.result.ResultBody;
import com.aifund.common.service.SystemConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/config")
public class SystemConfigController {

    @Autowired
    SystemConfigAdminService systemConfigAdminService;
    @Autowired
    SystemConfigService systemConfigService;

    @GetMapping("/configList")
    public PageResult<SystemConfig> configList(ConfigPageForm form){
        return systemConfigAdminService.page(form);
    }

    @PostMapping("/updateConfigValue")
    public ResultBody updateConfig(String key,String value){
        SystemConfig systemConfig = systemConfigService.getByKey(key);
        if(systemConfig!=null){
            systemConfig.setConfigValue(value);
            systemConfigService.save(systemConfig);
        }
        return ResultBody.success();
    }

}
